#ifndef __WARPSOL_H
#define __WARPSOL_H
#include <string>
#include <vector>
using std::string;
using std::vector;

/**
 ** A in memory representation of (layered) gray scale images with routines to read/write 
 ** Solexa-TIFF files as well as Jasper-encoded file types. Solexa does not apparently 
 ** support layered files, but it may be useful to store more thanone image in a Jasper 
 ** container for sake of better compression and/or more efficient file system access. 
 **/
class warpSol {
public:
  ~warpSol() { 
    clear();
  }

 warpSol() : _nx(-1), _ny(-1), _ns(-1) {}

  /** Number of images in memory **/
  int nPlane() { return _images.size(); }
  /** Width of image in  pixel **/
  int nx() { return _nx; }
  /** Height of image in  pixel **/
  int ny() { return _ny; }
  /** Number of samples in Solexa image (always 1) **/
  int ns() { return _ns; }

  /** Clear all images */
  void clear() {
    for(unsigned int i=0; i < nPlane(); ++i) {
      delete [] _images[i];
    }
    _images.clear();
    _filenames.clear();
    _nx = _ny = _ns = -1;
  }

  int readSolexa(string fnam);
  int writeSolexa(string fnam, int plane=0);
  int readJasper(string fnam, const char *format="jpc");
  int writeJasper(string fnam,   const char *options="",  const char *format="jpc");
  unsigned short int &getPixel(int x, int y, int s=0) {
    return _images[s][y * _nx + x];
  }
  
  void createImage(int nx, int ny, int ns=1);

private:
  vector<unsigned short int *> _images;
  vector<string> _filenames;
  int _nx, _ny, _ns;
  static const int SOLEXA_IMG_PRECISION;
};
#endif

